package face.pay.common.statistics.impl;

import face.pay.common.statistics.IuserStatisticsService;
import face.pay.constant.UserType;
import face.pay.dao.IncomeInfoDao;
import face.pay.dao.OrderInfoDao;
import face.pay.entity.UserInfo;
import face.pay.util.ResultMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * @Auther: zkj
 * @Date: 2019/8/6 17:18
 * @Description:
 */
@Service
public class UserStatisticsServiceImpl implements IuserStatisticsService {


    @Autowired
    private OrderInfoDao orderInfoDao;

    @Autowired
    private IncomeInfoDao incomeInfoDao;

    /**
     * map 存放输入参数 startTime endTime 以及其他参数
     * @param loginUser
     * @param params
     * @return
     */
    @Override
    public ResultMessage statistics(UserInfo loginUser,Map params) {

        /**
         * 商家订单 交易总额
         */
        params.put("userId",loginUser.getId());

        Map<String,Object> map =  new HashMap<String,Object>();

        Map<String,BigDecimal>  incomeMap = this.incomeInfoDao.tradeTotalAmoumt(params);

        /**
         * 非商家用户 获取收入里面对应原始金额
         */
        BigDecimal totalFee  = incomeMap.get("totalFee");

        BigDecimal totalMoney  = incomeMap.get("totalMoney");

        if(UserType.ENTERPRISE.equals(loginUser.getType())){
            /**
             * 商家用户 统计真实订单
             */
            totalFee = this.orderInfoDao.tradeTotalAmoumt(params);



        }
        /**
         * 交易总额
         */
        map.put("totalFee",totalFee);

        /**
         * 直接收益
         */
        map.put("totalMoney",totalMoney);
        /**
         *奖励
         */
        map.put("totalReward",new Integer(0));


        return ResultMessage.createSuccess(map);
    }
}
